home *** CD-ROM | disk | FTP | other *** search
/ The Original Shareware 1.1 / The Original Shareware (WeMake CDs)(Volume 1.1)(CDs, Inc)(1993).iso / 36 / qw10add.zip / COMM.DOC < prev    next >
Text File  |  1990-06-01  |  19KB  |  309 lines

  1. Communications programs such as terminal emulators, electronic mail programs, 
  2. and Bulletin Board Systems (BBS) are one of the most popular reasons for using 
  3. a multitasking environment.  It is well known that several computers can 
  4. "talk" to each other.  It might be getting information from a mainframe 
  5. database.  Perhaps sending electronic letters is more cost effective than 
  6. using a messenger service.  Or maybe you would like to download the latest 
  7. "freeware" program and yet get some other, more important work, done at the 
  8. same time.  Sometimes you have to redial a BBS dozens of times before it's 
  9. available.  With a multitasking program you can keep dialing while you do 
  10. something else.  Having instant access to communications programs and allowing 
  11. them to operate in the background while performing other tasks is one instance 
  12. of where multitasking programs prove very worthwhile.
  13.  
  14. This chapter will describe the important features of communications programs 
  15. as they regard multitasking, special considerations for multitasking, and 
  16. how to find and avoid problems with background communication.
  17.  
  18. While there are several popular multitasking environments available for IBM 
  19. PC and compatible computers, one of the most popular is DESQview.  DESQview 
  20. is designed to allow multiple off-the-shelf programs to be able to run at 
  21. the same time.  These programs can be of any type.  Depending on the amount 
  22. of memory and the type of program you have, it is possible to run programs 
  23. in either 640K or beyond with DESQview.  While the information in this 
  24. chapter will concentrate on suggestions for DESQview, most of the data is 
  25. appropriate to other multitasking environments as well.
  26.  
  27.  
  28. The Basics of Communications
  29.  
  30. The two most important concepts to understand for communications are ports 
  31. and interrupt request lines or IRQ.
  32.  
  33.  
  34. Communication Ports
  35.  
  36. The communication port is the place where the actual data is read or written.  
  37. When a value is to be sent to the serial line, whether it is to a modem or a 
  38. direct connection, the data is placed into a communication port.  The device 
  39. attached to the port, usually an Universal Asynchronous Receiver Transmitter 
  40. or UART (pronunced "YOU"-"ART"), converts the data from its current form of 8 
  41. bits, into a serial stream; each bit "follows" the others as though they were 
  42. going through a pipe.  The data in the computer is usually stored in groups 
  43. called bytes, which consist of 8 individual bits.  A communications line, also 
  44. called a serial line, only has one wire over which the data can be sent.  A 
  45. second line is used to receive.  The UART takes the byte of data to send and 
  46. "flattens" it, sending one bit at a time.  Another UART on the other side 
  47. "collects" the individual bits and then presents them as a byte to the 
  48. receiver.  This kind of operation can only really service one program at a 
  49. time, so in a multitasking environment you must have one communication port 
  50. (UART location) for each program which needs to communicate.
  51.  
  52. The standard UARTs can only send and receive one byte at a time.  If the 
  53. receiving UART has a byte ready and the computer does not read it before 
  54. another byte of data arrives, then the data has "overrun" and is lost.  It is 
  55. very important in a multitasking environment to make sure that the 
  56. communications lines are handled as quickly as possible to avoid overrun.  
  57. There do exist UARTs which can "buffer" more than one byte, and thus "hold on" 
  58. to some data until the computer is ready to receive it.  One of these is the 
  59. 16550A, which can buffer up to eight bytes before overrun occurs.  Converting 
  60. to a 16550A and software which understands it can be very useful when using 
  61. high speed communications while multitasking.
  62.  
  63. There are several ways to decide which port to use, but most communications 
  64. programs allow you to configure the one you want.  The most frequently used 
  65. ones are COM1 and COM2.  The usual port values for these are 3F8 and 2F8.  The 
  66. location for determining the exact port value is at 40:0 and 40:2, in memory 
  67. locations known as the BIOS data area.  A communication program normally looks 
  68. into this area to find out if a communication port exists, and if so, what the 
  69. port value to use is.  It is possible to have more ports, but IBM hasn't set a 
  70. standard way for finding more ports so each hardware vendor has made up a 
  71. method for extending the number of ports.  Only COM1 and COM2 can be sure to 
  72. work under all circumstances.
  73.  
  74. The method of looking at 40:0 and 40:2 to find the ports is not universal 
  75. though.  Some programmers assume that the port values are going to exist with 
  76. the particular numbers 3F8 and 2F8.  They are probably right 98% of the time, 
  77. but it is very confusing if you happen to have your computer set up 
  78. differently and a program doesn't work right.  I once saw a program which not 
  79. only assumed the port values, it also assumed that you wouldn't know how to 
  80. set them up, so it always took any data from either port.  You couldn't use a 
  81. mouse with it because the mouse driver program would have its data stolen!  It 
  82. also wouldn't allow a second communications program to be multitasked with it 
  83. either.  Most of the popular programs are quite well behaved, and this is 
  84. important for multitasking environments, since several programs and/or devices 
  85. will need to coexist in the same computer at one time.
  86.  
  87.  
  88. Interrupt Request Lines
  89.  
  90. An interrupt request line, or IRQ, is a way for a device, such as the 
  91. communications port (using an UART), to interrupt whatever the computer is 
  92. doing for a moment in order to handle something important; such as a character 
  93. which just came in on the serial line.  These interrupts are prioritized so 
  94. that the most important ones are handled first and can interrupt less 
  95. important ones. Thus, if a disk drive has just interrupted the computer and 
  96. then a serial line has some data ready, the serial line can "interrupt the 
  97. interrupt".  The disk, after all, can wait.  The serial line has to avoid 
  98. overrun.  A list of the standard IRQ values and their function is listed in 
  99. table 1.  DESQview modifies this list (when "Optimize communications" is "Y") 
  100. so that communications ports can interrupt everything else and be handled as 
  101. quickly as possible; you probably can't type as fast as another computer can 
  102. send you data.
  103.  
  104. The normal IRQs used for communications are IRQ4 (COM1) and IRQ3 (COM2).  Yes 
  105. this seems backwards.  My guess is that, when the IBM PC was being designed, 
  106. only one communication line was envisioned.  Some time later, after having too 
  107. many programs already written using COM1 to change it, they decided to add 
  108. another.  But the only unused IRQs were numbers 2 & 3.  IBM then chose IRQ3 
  109. for COM2.  Normally most of us wouldn't care about this except that the lower 
  110. the IRQ number, the higher its priority.  Thus while it seems anti-intuitive, 
  111. COM2 actually has a higher priority than COM1.  Thus, if you have two 
  112. communications programs running, the higher speed one should be on COM2.  Or, 
  113. if you have a serial mouse in addition to your modem, the modem should be on 
  114. COM2 since you can tolerate having the mouse a little "jumpy" in order to not 
  115. lose any incoming data.
  116.  
  117. For IBM's COM3 and COM4 they re-used IRQ 4 and IRQ 3.  How?  By using a 
  118. different port address and having a special indicator value which tells the 
  119. interrupt service routine whether the data is for COM1 or COM3 for instance.  
  120. But only specially configured programs know how to do this, and there is no 
  121. way for a multitasker such as DESQview to know which program is supposed to 
  122. get the data for a particular IRQ.  If each communications line uses a 
  123. different IRQ (say IRQ5 or IRQ2), then there is no ambiguity about which 
  124. program gets which data.  In addition, there are special drivers written, the 
  125. most popular is FOSSIL, which can perform the proper arbritration needed to 
  126. handle multiple serial requests.  These usually require special communications 
  127. hardware adapters.
  128.  
  129. All of the better communications programs use interrupt processing to handle 
  130. receiving of data; it's the most efficient method.  It's also best for 
  131. multitasking.  A program may be busy doing some calculation when a character 
  132. has been received by the UART.  The UART asserts the proper IRQ and the 
  133. current program is interrupted (that's why they're called interrupts) and the 
  134. program is put "on hold" for the moment.  The communication program has set up 
  135. a special routine to handle the interrupt, which usually reads the data from 
  136. the port and then stores it someplace to be handled later.  The interrupted 
  137. program is then resumed.  At some later time, the communication program gets 
  138. control and takes charge of the stored data.  Perhaps it is displayed on the 
  139. screen or stored in a file.  Often several characters have been received and 
  140. "buffered" before the "main" program can handle them.  This usually happens so 
  141. fast that you don't see anything unusual.
  142.  
  143. There are some programs which don't use interrupts.  They will "loop" or 
  144. "poll" the port waiting for the UART to signal that the data is ready and then 
  145. process it.  This is very wasteful of computer time, since the computer could 
  146. be doing many other things while waiting for the next piece of data.  These 
  147. programs are also especially bad for multitasking programs.  First, it wastes 
  148. time which could be used by other programs.  Second, since a mulitasker must 
  149. give a little bit of time to each program, the communications program is not 
  150. always in control, and if some data arrives and the communications program is 
  151. not active, the data will be lost.
  152.  
  153. In summary, the important aspects for multitasking are:
  154.  
  155.   a) a serial port can be used by only one program at a time
  156.   b) received data must be read as quickly as possible to avoid overrun
  157.   c) the number of serial ports is limited
  158.   d) the BIOS data area should be used to determine port numbers
  159.   e) communications interrupts are prioritized
  160.   f) most programs receive their serial input using interrupts
  161.  
  162.  
  163.  
  164. Special Considerations for Multitasking
  165.  
  166. Most programs, while unaware that multitasking may take place, are 
  167. reasonably well behaved.  This allows a program like DESQview to run 
  168. programs unmodified.  There are several things which you must take into 
  169. account:
  170.  
  171.  
  172. Writing to the Video Display
  173.  
  174. In order to work as fast as possible, many programs write directly to the 
  175. video display memory.  This provides the fastest possible video response.  
  176. It is also very bad for a multitasking environment.  If a program is going 
  177. to write directly to the video display while in the background, it will 
  178. "bleed through" on top of another program or programs.  This is probably 
  179. undesirable for most people.  What needs to be done is to either have a 
  180. program "behave" and use the DOS or BIOS calls provided to write to the 
  181. display, or to use a special interface which allows programs to continue to 
  182. think that they are writing directly to the video display, while actually 
  183. accessing another location which is then updated without interfering with 
  184. the other programs.  This can be done either by configuring the program to 
  185. "behave" or by the program detecting that it is in an environment and 
  186. converting itself to behave.
  187.  
  188. DESQview has a very efficient method for allowing programs to "think" that 
  189. they are writing to the video display while actually using an alternate (or 
  190. "shadow") area.  This method can automatically be invoked by a program in 
  191. DESQview, and many of the most popular programs use it, including Crosstalk 
  192. XVI and Mark IV, Procomm, ProYAM, PIBTerm, BitCOM, and PC-Talk.  On an 80386, 
  193. DESQview 386 can even make "misbehaved" programs stay away from the video 
  194. screen using special features available on the 80386.
  195.  
  196.  
  197. Keeping the Program in Memory
  198.  
  199. Most multitasking environments allow the programs running in them to be 
  200. "swapped" out of memory.  This allows you to suspend a program and then resume 
  201. it where you were at a later time.  Usually programs are swapped to the disk, 
  202. but it could also be to a RAM disk, network drive, or expanded memory.  Since 
  203. the serial ports can interrupt whatever is happening at any time, it is 
  204. essential that the program NEVER leave memory while communications are in 
  205. progress.  Thus a communications program must NOT be allowed to "swap".  Most 
  206. multitasking programs, including DESQview, allow these programs to be set up 
  207. so that swapping will not happen.
  208.  
  209. The problem is that forcing a program to be "non-swappable" can fragment 
  210. memory.  If you want to start a new program, and a non-swappable 
  211. communications program is in the way of the memory you need, then you won't be 
  212. able to run the new program until you close the communications program.  This 
  213. defeats the purpose of multitasking.  DESQview allows communications programs 
  214. which are not currently active (perhaps running but not connected to another 
  215. computer at the moment), to be swapped.  When this happens, DESQview will 
  216. "disconnect" the interrupt value from the program.  Then, if a character 
  217. happens to come in (maybe the phone rings), it will be ignored since the 
  218. special interrupt routine is no longer in memory.  DESQview will "reconnect" 
  219. the interrupt location when the program is swapped back in later.  You can 
  220. usually avoid memory fragmentation by running the communications programs 
  221. first which then leaves the rest of memory contiguous.  If you have expanded 
  222. memory, or an 80386, then it's possible to have the program run in expanded 
  223. memory and not have to worry about memory fragmentation.
  224.  
  225. Multiple communications programs
  226.  
  227. There is no real reason NOT to have more than one communication program 
  228. available at a time (if your wallet can afford it).  There are several 
  229. technical considerations though.
  230.  
  231. For instance, no two programs can use the same port at the same time.  The 
  232. communications ports are like your water faucet; you can make it go as fast 
  233. as you want but only one glass at a time can fit under it.  There are programs 
  234. which know how to put special information in the data stream to tell the 
  235. receiving end which program the data is for, but these programs normally 
  236. handle special purpose applications.  This allows a single serial line to 
  237. appear to be handling multiple sessions.  It works by embedding some special 
  238. information into the data to say "this is for program A", and then only that 
  239. program takes the data.  Very few services  use this feature.
  240.  
  241. In most cases, you can use a maximum of 2 communications programs at one time, 
  242. since IBM only officially recognizes COM1 and COM2 each on its own IRQ.  As 
  243. mentioned before, COM3 and COM4 don't usually have their own IRQ values so 
  244. they can't be used.  If an add-in board DOES have separate IRQ for each 
  245. communications port, then it is possible to have more than two programs 
  246. communicating at one time.
  247.  
  248.  
  249. Communication Speed
  250.  
  251.  
  252. The computer itself can only perform one function at a time.  A multitasking 
  253. program such as DESQview divides the computers attention between several 
  254. different programs for short periods of time.  Since the computer is so fast, 
  255. each of these programs appear to be running at the same time, but obviously 
  256. they are not.  Thus, when multitasking, each program is running slower than it 
  257. normally would.  This is usually not a major problem, since most programs 
  258. spend most of their time waiting for input and then process for some time and 
  259. go back to waiting.  But a communications program must be ready to take its 
  260. data when it arrives.  As mentioned before, interrupts are used to get the 
  261. computer's attention when the data is ready.  But if the data is coming in too 
  262. fast, then the interrupt routine cannot process the information before the 
  263. next byte arrives.
  264.  
  265. For various reasons, there are some standard rates at which computers 
  266. communicate.  Usually 110, 300, 600, 1200, 2400, 4800, and 9600 bits 
  267. per second.  Since there are a few bits of control information being sent, 
  268. these numbers translate into about 10, 30, 60, 120, 240, 480, and 960 
  269. characters per second.  Even faster speeds are being used in some special 
  270. applications.  At the slower speeds, the computer has plenty of time to digest 
  271. the incoming data and be ready for more.  In the time not used to process 
  272. serial data, there's time to do other work such as word processing, 
  273. spreadsheets or compiling.
  274.  
  275. When communicating at 240 characters per second, the characters arrive about 
  276. once every 4 milliseconds (every 4 thousandths of a second).  Even slow 8088 
  277. computers can usually read in these characters using about 500 instructions or 
  278. so, which usually takes less than 1 millisecond.  This would seem to leave 
  279. some time for other programs to get some processing done, and it does.  But 
  280. remember that each program gets to process itself for some time, and then 
  281. control is passed to another program.  Thus quite a few characters (maybe 20 
  282. or so) will have been "buffered" or stored before the communications program 
  283. gets its turn to  do something other than just read the data.  At higher 
  284. communications speeds (such as 4800 or 9600), the amount of time to process 
  285. the characters remains the same, but the rate at which they arrive is faster.  
  286. Thus the "bufffer" needs to be 2 or 4 times larger in order to accomodate the 
  287. larger number of arriving characters.  Most communication programs have pretty 
  288. good size buffers, and many allow you to increase the size to prevent buffer 
  289. overflow.
  290.  
  291. From these calculations, it would seem that even an 8088 could handle 9600 
  292. bits per second communications with characters arriving about every 1 
  293. millisecond and about a half millisecond to process it.  But that only leaves 
  294. about a half millisecond to do something else (such as display the information 
  295. on the screen).  The solution to to use a faster computer when using faster 
  296. communications speeds.  You should figure that you want to split the time for 
  297. communications programs and other programs evenly, and you should take less 
  298. than half the available time processing characters.  So, assuming it takes 
  299. about 500 instructions to handle each character, you need to find out how long 
  300. it takes to process that many instructions for your computer.  A 4.77 MHZ 8088 
  301. takes about 1 millisecond.  An 8MHz 80286 takes about a half millisecond, and 
  302. a 16MHz 80386 takes about one fourth millisecond.  Leaving time for other 
  303. fucntions essentially means that you can multitask 2400 on an 8088, 9600 on an 
  304. 80286, and higher on an 803836 and still leave time for other programs to get 
  305. some usefull work done.
  306.  
  307. If you run more than one communications program, then you should allow even 
  308. more time, since there has to be some extra processing to move between 
  309.